package ilearning.demo.controller;

import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.learning.dynamic.executor.executor.DynamicExecutor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author Wang Xu
 * @date 2023/11/8
 */
@RequestMapping("/nacos")
@RestController
@RefreshScope
public class NacosConfigTestController {
    @Value("${demo.test.k1:1111}")
    private String v1;

    @Resource
    NacosConfigProperties nacosConfigProperties;
//    @Resource
    private DynamicExecutor dynamicExecutor;


    @GetMapping("/getv")
    public String getV() {
//        try {
//            ConfigService configService = nacosConfigProperties.configServiceInstance();
//            String config = configService.getConfig("nacos-dy-ds-conf", "group-test1", 1000);
//            System.out.println(config);
//        } catch (NacosException e) {
//            e.printStackTrace();
//        }
        return v1;
    }

    @GetMapping("/getdec")
    public String getDEC() {
        if (Objects.nonNull(dynamicExecutor)) {
            return "====== MaximumPoolSize = " + dynamicExecutor.getMaximumPoolSize()
                    + "; CorePoolSize = " + dynamicExecutor.getCorePoolSize()
                    + "; PoolName = " + dynamicExecutor.getPoolName();
        }
        return "eeeeeeeee";
    }
}